package com.spring_activemq.mq.provider;

import javax.annotation.Resource;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Service;

@Service("activeMQProvider")
public class ActiveMQProvider {

	@Resource(name = "p2pJmsTemplate")
	private JmsTemplate p2pJmsTemplate;

	@Resource(name = "pubSubJmsTemplate")
	private JmsTemplate pubSubJmsTemplate;

	public void sendMessage(final String info) {
		p2pJmsTemplate.send(new MessageCreator() {

			public Message createMessage(Session session) throws JMSException {
				return session.createTextMessage(info);
			}
		});
	}

	public void sendPubSupTopic(final String info) {
		pubSubJmsTemplate.send(new MessageCreator() {

			public Message createMessage(Session session) throws JMSException {
				return session.createTextMessage(info);
			}
		});
	}

}
